home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / util / misc / gadmget1_5.lha / GadMget1.5 / Source / GadMget.c next >
C/C++ Source or Header  |  1994-10-01  |  53KB  |  2,320 lines

  1. /* GadMGet.c  by Jeremy Friesner -- jfriesne@ucsd.edu  
  2.    Version 1.5, released 1 October 1994 */
  3.  
  4. #ifndef MGET_C
  5. #define MGET_C
  6.  
  7. #define INTUI_V36_NAMES_ONLY
  8. #define MAXFILELINELENGTH 300
  9. #define CHAR_SPACE 32
  10. #define INVALID 666
  11.  
  12. #include "GadMget.h"
  13.  
  14. extern UWORD lastcode;
  15. extern struct NewGadget mgetNGad[];
  16. extern struct NewMenu mgetNewMenu[];
  17. extern struct Window *findwindow;
  18. extern struct AppMessage *amsg;
  19. extern struct MsgPort *awport;
  20. extern struct AppWindow *appwin;
  21. extern struct TextAttr listfont;
  22.  
  23. extern ULONG appwinsig;
  24.  
  25.  
  26. FILE *fpOut = stdout;
  27. int IntuitionBase; 
  28. ULONG winopenerror, lockscrnerror;
  29. ULONG handlereturn;
  30. BOOL done=FALSE,BStartedFromWB=FALSE;
  31. char windowtitle[95] = "Loading...";
  32. char sListFontName[36] = "";
  33. int nListFontSize = 0;  /* Default to a bad value */
  34. char version[] = "$VER: GadMget V1.5";
  35. char template[] = "Template:  GadMGet FILE/A,OUTPUT/K,LINELENGTH/K,TOP/K,LEFT/K,\
  36. WIDTH/K,HEIGHT/K,PUBSCREEN/K,WBSCREEN/S,DEFPUBSCREEN/S,NOFILES/S,GETREADMES/S,\
  37. NOPARSE/S,CASESENSITIVE/S,NOCOMMAND/S,NOSPLIT/S,NOAPPWINDOW/S,COMMAND/K,\
  38. NOSIMPLEPATHS/S,NOCD/S,HEADER/K,FOOTER/K,FONT/K,FONTSIZE/K\n,KEEPBLANKLINES/S";
  39. char pnamestring[20],searchstring[MAXFILELINELENGTH];
  40. char szPubScreenName[40],*pubscreenname = NULL,defDir[200],defFile[40];
  41. char szCommandString[40] = "mget";
  42. char inputfile[300]="ram:RECENT";
  43. char szHeaderFile[300];
  44. char szFooterFile[300];
  45. int nTopListTop;
  46. int nTopListHeight;
  47.     
  48.  
  49. /* default flags */
  50. int screentype             = USE_CUSTOMSCREEN,    
  51.      getreadmes                = 0, 
  52.      filesflag              = 1,                             /* get .lha files */
  53.      index                     = 0,                             /* start find at top */
  54.      filelist_length         = 0,                             /* no files loaded */
  55.      simplepaths             = 1,                             /* don't use ncftp style mgets */
  56.      casesensitive            = 0,                    
  57.      maxoutputlinelength = 254,                         /* shell's limit */
  58.      linelengthrequest     = 0,                             /* subwindow is for string searches */
  59.      appwindow                 = 1,                            /* = YES */
  60.      added_bytes             = 0,                            /* used for debugging-- tracks */
  61.                                                                  /* the # of bytes allocated */
  62.      files_selected         = 0,                             /* no files selected */
  63.      screenisopen             = 0,                             /* = NO */
  64.      windowisopen             = 0,                            /* = NO */
  65.      noparse                 = 0,                             /* = yes, parse */
  66.      nocommand                = 0,                             /* = yes, generate command */
  67.      nosplit                 = 0,                             /* = yes, split */
  68.      nocd                        = 0,                            /* = generate CD commands */
  69.      mgetNGad_height         = 248,                        /* default first listview height */
  70.      keepblanklines        = 0;                    /* = don't show blank lines */
  71.  
  72. ULONG kbytes_selected = 0;                                
  73.      
  74. UWORD windowwidth     = 99999,                            /* window will be sized to fill */
  75.         windowheight     = 99999,                            /* screen unless these are */
  76.         windowtop         = 0,                                 /* overridden by parameters */
  77.         windowleft         = 0;
  78.         
  79.  
  80. void *findvi = NULL;
  81.  
  82. struct Library *Intuitionbase            = NULL;
  83. struct GfxBase *GraphicsBase            = NULL;
  84. struct Library *GadToolsBase            = NULL;
  85. struct Library *UtilityBase            = NULL;
  86. struct Library *AslBase                    = NULL;
  87. struct Library *IconBase                = NULL;
  88. struct Library *WorkbenchBase            = NULL;
  89. struct WBArg *argptr = NULL;
  90.  
  91. struct IntuiMessage *message                 = NULL;
  92. struct List *filelist                         = NULL, 
  93.                 *getlist                         = NULL;
  94. struct Node *search_current                 = NULL;
  95. struct Gadget *findgadlist                 = NULL;
  96. struct TextFont *listfontdata = NULL;
  97.  
  98. __chip UWORD waitPointer[] =
  99.     {
  100.     0x0000, 0x0000,
  101.     
  102.     0x0400, 0x07c0,
  103.     0x0000, 0x07c0,
  104.     0x0100, 0x0380,
  105.     0x0000, 0x07e0,
  106.     0x07c0, 0x1ff8,
  107.     0x1ff0, 0x3fec,
  108.     0x3ff8, 0x7fde,
  109.     0x3ff8, 0x7fbe,
  110.     0x7ffc, 0xff7f,
  111.     0x7efc, 0xffff,
  112.     0x7ffc, 0xffff,
  113.     0x3ff8, 0x7ffe,
  114.     0x3ff8, 0x7ffe,
  115.     0x1ff0, 0x3ffc,
  116.     0x07c0, 0x1ff8,
  117.     0x0000, 0x07e0,
  118.     
  119.     0x0000, 0x0000};
  120.     
  121.  
  122.  
  123.  
  124.  
  125.  
  126. void debug(int a)
  127. {
  128. fprintf(fpOut,"debug  %i\n",a);
  129. Delay(80);
  130. }
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. int listviewgadgetClicked (VOID)
  138. {
  139. int i;
  140. struct Node *current = filelist->lh_Head;
  141. struct Gadget *toplist = mgetGadgets[0];
  142. struct Gadget *botlist = mgetGadgets[1];
  143. char *dataline = NULL;
  144. int minlinelength = 1,oktosend = 1;
  145.  
  146.  if (keepblanklines == 1) minlinelength = 0;
  147.  
  148.  for (i=0; i<lastcode; i++) current = current->ln_Succ;
  149.  
  150.  if (current != NULL)
  151.     {
  152.     /* check to make sure string is a valid file line */
  153.     dataline = current->ln_Name;
  154.     if (dataline == NULL) oktosend = 0;
  155.     if (strlen(current->ln_Name) < minlinelength) oktosend = 0;
  156.         
  157.     if (!noparse)
  158.         {
  159.         if ((dataline[0] < '0')||(dataline[0] > 'z')) oktosend = 0;
  160.         if ((dataline[35] != 'K')&&(dataline[35] != 'M')&&(dataline[35] != '?')) oktosend = 0;
  161.         if (dataline[21] < '0') oktosend = 0;
  162.         if ((filesflag == 0)&&(dataline[36] != '+')) oktosend = 0;
  163.         }    
  164.     if (oktosend)
  165.         {
  166.         UpdateByteCount(dataline,1);
  167.         /* Take it out of filelist */
  168.         GT_SetGadgetAttrs(toplist, mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  169.         Remove(current);
  170.         GT_SetGadgetAttrs(toplist, mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  171.     
  172.         if (search_current == current) search_current = current->ln_Succ;
  173.         
  174.         current->ln_Succ = NULL;        /* Clear now invalid field */
  175.         
  176.         /* And insert it in getlist */
  177.         /* first detach list to modify it */
  178.         GT_SetGadgetAttrs(botlist, mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  179.         AddTail(getlist,current);
  180.         GT_SetGadgetAttrs(botlist, mgetWnd, NULL, GTLV_Labels, getlist, TAG_END);
  181.         files_selected++;
  182.         filelist_length--;
  183.         index--;                /* Is this the best thing, short of a search through the */
  184.         if (index<0) index = 0;    /* Whole list for the index of current?  */
  185.         ChangeWindowTitle();
  186.         }
  187.     }
  188.     
  189. }
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198. int list2Clicked (VOID)
  199. {
  200. /* This function will move a clicked item from the lower list to the upper one */
  201.  
  202. int i;
  203. struct Node *current = getlist->lh_Head;
  204. struct Gadget *toplist = mgetGadgets[0];
  205. struct Gadget *botlist = mgetGadgets[1];
  206.  
  207.  for (i=0; i<lastcode; i++)
  208.     {
  209.     current = current->ln_Succ;
  210.     }
  211.  
  212. UpdateByteCount(current->ln_Name,-1);
  213.  
  214. /* Take it out of getlist */
  215. GT_SetGadgetAttrs(botlist, mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  216. Remove(current);
  217. GT_SetGadgetAttrs(botlist, mgetWnd, NULL, GTLV_Labels, getlist, TAG_END);
  218.  
  219. current->ln_Succ = NULL;        /* Clear now invalid field */
  220.  
  221. /* And insert it in filelist */
  222. GT_SetGadgetAttrs(toplist, mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  223. AddTail(filelist,current);
  224. GT_SetGadgetAttrs(toplist, mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  225. /* and that's it! */
  226.  
  227. files_selected--;
  228. filelist_length++;
  229. ChangeWindowTitle();
  230. }
  231.  
  232.  
  233.  
  234. void SortByDirectory(struct List *thislist)
  235. {
  236.     /* a simple swap-sort */
  237.     int nSwappedThisPass = 1;        /* to start the loop */
  238.     struct Node *current, *past;
  239.     char sBuffer1[11], sBuffer2[11];
  240.     
  241.     
  242.     if (thislist == NULL)
  243.     {
  244.         return;
  245.     }
  246.     
  247.     while (nSwappedThisPass > 0)
  248.     {
  249.         /* start a pass */
  250.         past = thislist->lh_Head;
  251.         if (past == NULL)
  252.         {
  253.             /* empty list ! */
  254.             return;
  255.         }
  256.         current = past->ln_Succ;
  257.  
  258.         nSwappedThisPass = 0;        /* start with none recorded */
  259.  
  260.         while (current != NULL)            
  261.         {
  262.             if ((current->ln_Name != NULL)&&(past->ln_Name != NULL))
  263.             {
  264.                 memset(sBuffer1,NUL,sizeof(sBuffer1));
  265.                 memset(sBuffer2,NUL,sizeof(sBuffer2));
  266.                 
  267.                 strncpy(sBuffer1,past->ln_Name+21,sizeof(sBuffer1)-1);
  268.                 strncpy(sBuffer2,current->ln_Name+21,sizeof(sBuffer2)-1);
  269.             
  270.                 if ((strchr(sBuffer1,'/') != NULL)&&
  271.                     (strchr(sBuffer2,'/') != NULL)&&
  272.                      (strncmp(sBuffer1,sBuffer2,sizeof(sBuffer1)) > 0))
  273.                     {
  274.                     /* Swap the two nodes */
  275.                     Remove(past);                            /* take previous out of list */
  276.                     Insert(thislist, past, current);    /* and put it back in after current */
  277.             
  278.                     nSwappedThisPass++;
  279.                     }
  280.             }
  281.                         
  282.             past = current;
  283.             current = current->ln_Succ;
  284.         }
  285.     }
  286.             
  287.     return;
  288. }
  289.         
  290.         
  291.  
  292.  
  293. int OutputList(struct List *thislist)
  294. {
  295. #define LASTDIRBUFSIZE 30
  296.  
  297.  char *j, *j2, *p;
  298.  int k,l,z,next_bytes,putnameOK = 0,putcommandOK = 1; 
  299.  int printed_bytes = maxoutputlinelength - 1, printreturnfirst = 0;
  300.  char outname[MAXFILELINELENGTH],szLastDir[LASTDIRBUFSIZE];
  301.  struct Node *current;
  302.  
  303.  
  304.  memset(szLastDir,NUL,LASTDIRBUFSIZE);
  305.  
  306.  /* If we are using "simple" output, sorting the list by directory will mean
  307.     fewer "cd" commands.  If not, we might as well let the user decide the
  308.     download order! */
  309.  if (simplepaths == 1) SortByDirectory(thislist);
  310.     
  311.  /* Get any readme files first, so user can browse them while d/l'ing the rest */
  312.  if (getreadmes)
  313.     {
  314.     current = thislist->lh_Head;
  315.      while (current != NULL)
  316.           {
  317.         /* watch out for empty nodes! */
  318.         if (current->ln_Name != NULL) 
  319.             {
  320.             z = strlen(current->ln_Name);
  321.             /* Extra filtering code, borrowed from mgetlistviewclicked()... */
  322.             if ((current->ln_Name[0] < '0')||(current->ln_Name [0] > 'z')) z = 0;
  323.             if ((current->ln_Name[35] != 'K')&&(current->ln_Name[35] != 'M')&&(current->ln_Name[35] != '?')) z = 0;
  324.             if (current->ln_Name[21] < '0') z = 0;
  325.             if ((filesflag == 0)&&(current->ln_Name[36] != '+')) z = 0;
  326.             /* end code from mgetlistviewclicked() ... */
  327.             }
  328.             else z=0;
  329.         
  330.         
  331.         
  332.         if (z>21)
  333.             {
  334.             j = strchr(current->ln_Name,32);       /* address of first space after filename */
  335.             k = j - current->ln_Name;               /* length of filename */
  336.             j2 = strchr(current->ln_Name+21,32);    /* address of directory of file */
  337.             l = j2 - (current->ln_Name) - 21;        /* length of directory */
  338.     
  339.             if ((k<22)&&(k>0)&&(l<12)&&(l>2))
  340.                 {
  341.                 memset(outname,NUL,MAXFILELINELENGTH);
  342.                 strncat(outname,current->ln_Name+21,l);
  343.                 
  344.                 /* Here we have the directory name--see if it's different, generate cd */
  345.                 if ((current->ln_Name[36] == '+')&&
  346.                     (nocd == 0)&&
  347.                     (simplepaths == 1)&&
  348.                     (strncmp(szLastDir,outname,LASTDIRBUFSIZE) != 0)) 
  349.                 {
  350.                     memset(szLastDir,NUL,LASTDIRBUFSIZE);
  351.                     GenerateCDCommand(&printreturnfirst, &printed_bytes, szLastDir, outname);
  352.                     putnameOK = 1;
  353.                     putcommandOK = 0;
  354.                 }
  355.                 
  356.                 if (simplepaths == 1)
  357.                 {    
  358.                     /* remove path so it won't be printed again in the mget command */
  359.                     memset(outname,NUL,sizeof(outname));
  360.                 }
  361.                 else
  362.                 {
  363.                     strncat(outname,"/",1);
  364.                 }
  365.                 
  366.                 strncat(outname,current->ln_Name,k);
  367.                 outname[79]=0;    /* just in case, we'll reterminate the string */            
  368.             
  369.                 if (current->ln_Name[36] == '+')
  370.                     {    
  371.                     /* find the last '.' in outname, and change whatever's after it to 'readme'! */
  372.                     p = strrchr(outname,'.');
  373.                     
  374.                     /* and if there is no "." ? */
  375.                     if (p == NULL)
  376.                     {
  377.                         strcat(outname,".");
  378.                         p = strrchr(outname,'.');
  379.                     }
  380.                     
  381.                     strcpy(p+1,"readme");
  382.                     
  383.                     next_bytes = strlen(outname) + 1;    /* + 1 for the space */
  384.                     if ((next_bytes>3)&&(next_bytes<39))
  385.                         {
  386.                         if ((putcommandOK == 1)&&(!nosplit)&&((printed_bytes + next_bytes) > maxoutputlinelength))
  387.                             {
  388.                             PrintCommandString(&printreturnfirst, &printed_bytes);            
  389.                             putnameOK = 1;
  390.                             }            
  391.                         fprintf(fpOut,"%s ",outname);
  392.                         printed_bytes = printed_bytes + next_bytes;
  393.                         putcommandOK = 1;
  394.                         }
  395.                     }
  396.                 }
  397.             }
  398.         current = current->ln_Succ;    
  399.         }
  400.     }        
  401.  
  402.  if (filesflag)
  403.  {    
  404.  current = thislist->lh_Head;    
  405.     while (current != NULL)
  406.     {
  407.         /* watch out for empty nodes! */
  408.         if (current->ln_Name != NULL)
  409.             {
  410.             z = strlen(current->ln_Name);
  411.             /* Extra filtering code, borrowed from mgetlistviewclicked()... */
  412.             if ((current->ln_Name[0] < '0')||(current->ln_Name [0] > 'z')) z = 0;
  413.             if ((current->ln_Name[35] != 'K')&&(current->ln_Name[35] != 'M')&&(current->ln_Name[35] != '?')) z = 0;
  414.             if (current->ln_Name[21] < '0') z = 0;
  415.             if ((filesflag == 0)&&(current->ln_Name[36] != '+')) z = 0;
  416.             /* end code from mgetlistviewclicked() ... */
  417.             }
  418.             else
  419.             {
  420.             z=0;
  421.             }
  422.         
  423.         if (z>21)
  424.             {
  425.             j = strchr(current->ln_Name,32);   /* address of first space after filename */
  426.             k = j - current->ln_Name;           /* length of filename */
  427.             j2 = strchr(current->ln_Name+21,32);   /* address of directory of file */
  428.             l = j2 - (current->ln_Name) - 21;        /* length of directory */
  429.     
  430.             if ((k<22)&&(k>0)&&(l<12)&&(l>2))
  431.                 {
  432.                 memset(outname,NUL,MAXFILELINELENGTH);
  433.                 strncat(outname,current->ln_Name+21,l);
  434.  
  435.                 /* Here we have the directory name--see if it's different, generate cd */
  436.                 if ((nocd == 0)&&
  437.                      (simplepaths == 1)&&
  438.                      (strncmp(szLastDir,outname,LASTDIRBUFSIZE) != 0)) 
  439.                 {
  440.                     memset(szLastDir,NUL,LASTDIRBUFSIZE);
  441.                     GenerateCDCommand(&printreturnfirst, &printed_bytes, szLastDir, outname);
  442.                     putcommandOK = 0;
  443.                     putnameOK = 1;
  444.                 }
  445.                 
  446.                 if (simplepaths == 1)
  447.                 {    
  448.                     /* remove path so it won't be printed again in the mget command */
  449.                     memset(outname,NUL,sizeof(outname));
  450.                 }
  451.                 else
  452.                 {
  453.                     strncat(outname,"/",1);
  454.                 }
  455.                 
  456.                 
  457.                 strncat(outname,current->ln_Name,k);
  458.                 outname[79]=0;    /* just in case, we'll reterminate the string */            
  459.                 if (filesflag)
  460.                     {    
  461.                     next_bytes = strlen(outname) + 1;    /* + 1 for the space */
  462.                     if ((next_bytes>3)&&(next_bytes<33))
  463.                         {
  464.                         if ((putcommandOK == 1)&&(!nosplit)&&((printed_bytes + next_bytes) > maxoutputlinelength))
  465.                             {
  466.                             PrintCommandString(&printreturnfirst, &printed_bytes);    
  467.                             putnameOK = 1;
  468.                             }            
  469.                         fprintf(fpOut,"%s ",outname);
  470.                         putcommandOK = 1;
  471.                         printed_bytes = printed_bytes + next_bytes;
  472.                         }
  473.                     }
  474.                 }
  475.             }    
  476.         current = current->ln_Succ;    
  477.         }
  478.     }
  479. return(1);
  480. }
  481.  
  482.  
  483.  
  484.  
  485. void PrintCommandString(int *printreturnfirst, int *printed_bytes)
  486. {
  487.     if (*printreturnfirst) fprintf(fpOut,"\r\n"); 
  488.     *printreturnfirst = 1;
  489.         
  490.     if (nocommand) 
  491.     {
  492.         *printed_bytes = 0;
  493.     }
  494.     else
  495.     {
  496.         fprintf(fpOut,"%s ",szCommandString);
  497.         *printreturnfirst = 1;
  498.         *printed_bytes = strlen(szCommandString) + 1;    /* reset counter for next batch */
  499.     }
  500.     return;
  501. }
  502.  
  503.  
  504.  
  505.  
  506. void GenerateCDCommand(int *printreturnfirst, int *printed_bytes, char *szLastDir, char *outname)
  507. {
  508.     if (*printreturnfirst) fprintf(fpOut,"\r\n");
  509.     fprintf(fpOut,"cd ");
  510.                 
  511.     /* On the first item, we will be starting at the aminet root
  512.        directory, so we won't need to print the ../.. .  After that,
  513.         though, we will.  printreturnfirst serves nicely to tell
  514.         whether or not we're in the first iteration. */   
  515.     
  516.     if (*printreturnfirst == 1) fprintf(fpOut,"../../");
  517.             
  518.     fprintf(fpOut,"%s",outname);
  519.     *printreturnfirst = 1;
  520.     PrintCommandString(printreturnfirst, printed_bytes);
  521.  
  522.     /* update buffer */    
  523.     strncpy(szLastDir,outname,30);    
  524.  
  525.     return;
  526. }            
  527.  
  528.  
  529.  
  530. int RawOutputList(struct List *thislist)
  531. {
  532. struct Node *current = thislist->lh_Head;
  533. int minlinelength = 1;
  534.  
  535.  if (keepblanklines == 1) minlinelength = 0;
  536.       
  537.  while (current != NULL)
  538.     {    
  539.     if ((current->ln_Name != NULL)&&(current->ln_Name[0] < 128)&&(strlen(current->ln_Name) >= minlinelength))
  540.         {
  541.             if (current->ln_Name[0] < 14) 
  542.             {
  543.                 fprintf(fpOut,"\n",current->ln_Name);
  544.             }
  545.             else
  546.             {
  547.                 fprintf(fpOut,"%.300s\n",current->ln_Name);
  548.             }
  549.         }
  550.     current = current->ln_Succ;
  551.     }
  552. return(1);
  553. }
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563. int MakeReq(char *sText, char *sTitle, char *sGadgets)
  564. {
  565. struct EasyStruct myreq;
  566. LONG number = 0L;
  567. int nResult;
  568. char sDefaultTitle[] = "GadMGet Error";
  569.  
  570. if (sTitle == NULL) sTitle = sDefaultTitle;
  571. if (sText == NULL) sText = sDefaultTitle;
  572. if (sGadgets == NULL) sGadgets = "OK";
  573.  
  574. myreq.es_TextFormat   = sText;
  575. myreq.es_Title        = sTitle;
  576. myreq.es_GadgetFormat = sGadgets;
  577.  
  578. if (mgetWnd != NULL) SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  579. nResult = EasyRequest(mgetWnd, &myreq, NULL, NULL, number);
  580. if (mgetWnd != NULL) ClearPointer(mgetWnd);
  581.  
  582. return(nResult);
  583. }
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596. int mgetabout (VOID)
  597. {
  598. char sAboutText[100];
  599.  
  600. strcpy(sAboutText,pnamestring);
  601. strcat(sAboutText,"\n%s\n\nby Jeremy Friesner\njfriesne@ucsd.edu\n");
  602. MakeReq(sAboutText,"About GadMGet","Hey, Cool!");
  603. return(1);
  604. }
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613. int mgetquit (VOID)
  614. {
  615. done=TRUE;
  616. }
  617.  
  618.  
  619.  
  620.  
  621.  
  622.  
  623. int mgetcase (VOID)
  624. {
  625. if (casesensitive == 0) casesensitive = 1; else casesensitive = 0;
  626. SetMenuValues();
  627. }
  628.  
  629.  
  630.  
  631.  
  632. int mgetCD (VOID)
  633. {
  634. if (simplepaths == 0) simplepaths = 1; else simplepaths = 0;
  635. SetMenuValues();
  636. }
  637.  
  638.  
  639.  
  640.  
  641. int mgetfind (VOID)
  642. {
  643. ULONG winsig, signals;
  644. int done = 0, found = 0;
  645. int fwindowwidth = 450, fwindowheight = 35 + Scr->RastPort.TxHeight;
  646. int fwindowleft = (mgetLeft + (windowwidth/2) - (fwindowwidth/2));
  647. int fwindowtop  = (mgetTop  + (windowheight/2)- (fwindowheight/2));
  648. struct NewGadget stringGad;
  649. struct IntuiMessage *imsg;
  650. struct Gadget *newgad = NULL;
  651. char numstring[10], *ss = searchstring;
  652. char *wp = NULL,windowtitlestring0[] = "Search Window", windowtitlestring1[] = "Line Length Window";
  653.     
  654. index = 0;        /* start searching at top again! */
  655.  
  656. findvi  = GetVisualInfo(Scr, TAG_END);
  657. if (findvi == NULL) return(0);
  658. if (findwindow != NULL) return(0);
  659.  
  660.  
  661. if (fwindowleft < 0) fwindowleft = mgetLeft;
  662. if (fwindowheight < 0) fwindowtop = mgetTop;
  663.  
  664.  newgad = CreateContext(&findgadlist);
  665.  if (newgad == 0)
  666.     {
  667.     MakeReq("Couldn't create findwindow gad context!\n",NULL,"Dammit!");
  668.     return(0);
  669.     }
  670.  
  671.  if (newgad == NULL) return(0);
  672.  
  673. stringGad.ng_TextAttr     = &topaz8;    /* Cant figure out how to get system default into a TextAttr!  No name string available! */
  674. stringGad.ng_VisualInfo  = findvi;
  675. stringGad.ng_LeftEdge     = 5;
  676. stringGad.ng_TopEdge        = 18 + Scr->RastPort.TxHeight;
  677. stringGad.ng_Width         = (fwindowwidth-10);
  678. stringGad.ng_Height         = 13;
  679. stringGad.ng_GadgetText  = "Please enter search string.";
  680. stringGad.ng_GadgetID     = 35;    
  681. stringGad.ng_Flags         = PLACETEXT_ABOVE;
  682.  
  683. if (linelengthrequest == 1) 
  684.     {
  685.     wp = windowtitlestring1;
  686.     stringGad.ng_GadgetText = "Please enter new maximum line length.";
  687.     sprintf(numstring,"%i\0",maxoutputlinelength);    
  688.     ss = numstring;
  689.     }
  690.     else
  691.     wp = windowtitlestring0;
  692.     
  693.  
  694.  newgad = CreateGadget(STRING_KIND, newgad, &stringGad, 
  695.                   GTST_String, ss, 
  696.                   STRINGA_Justification, GACT_STRINGCENTER, 
  697.                   GA_Immediate, TRUE,
  698.                   TAG_END);  
  699.  
  700. if (newgad == NULL) 
  701.     {
  702.     FreeGadgets(findgadlist);
  703.     FreeVisualInfo(findvi);
  704.     return(0);
  705.     }
  706.  
  707.  if (GadToolsBase->lib_Version == 37)
  708.     {
  709.     /* Only do it the "illegal" way under v37.  GA_Immediate in the CreateGadget
  710.        line, above, won't work under v37 but will on later releases. */
  711.     newgad->Activation |= GACT_IMMEDIATE; 
  712.     }    
  713.  
  714.  switch (screentype)
  715.     {
  716.     case USE_PUBSCREEN:
  717.         findwindow = OpenWindowTags(NULL,
  718.                 WA_Left,        fwindowleft,
  719.                 WA_Top,        fwindowtop,
  720.                 WA_Width,         fwindowwidth,
  721.                 WA_Height,    fwindowheight,
  722.                 WA_PubScreen,    Scr,
  723.                 WA_PubScreenFallBack, TRUE,
  724.                 WA_IDCMP,        STRINGIDCMP|IDCMP_CLOSEWINDOW|
  725.                             IDCMP_REFRESHWINDOW|IDCMP_ACTIVEWINDOW,
  726.                 WA_Flags,        WFLG_DRAGBAR|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  727.                 WA_Gadgets,    findgadlist,
  728.                 WA_Title,         wp,
  729.                 WA_ScreenTitle,    pnamestring,
  730.                 TAG_DONE );
  731.         break;
  732.     case USE_CUSTOMSCREEN:
  733.         findwindow = OpenWindowTags(NULL,
  734.                 WA_Left,        fwindowleft,
  735.                 WA_Top,        fwindowtop,
  736.                 WA_Width,         fwindowwidth,
  737.                 WA_Height,    fwindowheight,
  738.                 WA_CustomScreen, Scr,
  739.                 WA_IDCMP,        STRINGIDCMP|IDCMP_CLOSEWINDOW|
  740.                             IDCMP_REFRESHWINDOW|IDCMP_ACTIVEWINDOW,
  741.                 WA_Flags,        WFLG_DRAGBAR|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  742.                 WA_Gadgets,    findgadlist,
  743.                 WA_Title,         wp,
  744.                 WA_ScreenTitle,    pnamestring,
  745.                 WA_CustomScreen,    Scr,
  746.                 TAG_DONE );
  747.         break;
  748.     case USE_WBSCREEN:
  749.         findwindow = OpenWindowTags(NULL,
  750.                 WA_Left,        fwindowleft,
  751.                 WA_Top,        fwindowtop,
  752.                 WA_Width,         fwindowwidth,
  753.                 WA_Height,    fwindowheight,
  754.                 WA_IDCMP,        STRINGIDCMP|IDCMP_CLOSEWINDOW|
  755.                             IDCMP_REFRESHWINDOW|IDCMP_ACTIVEWINDOW,
  756.                 WA_Flags,        WFLG_DRAGBAR|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  757.                 WA_Gadgets,    findgadlist,
  758.                 WA_Title,         wp,
  759.                 WA_ScreenTitle,    pnamestring,
  760.                 TAG_DONE );
  761.         break;
  762.     }
  763.  
  764. if (findwindow == NULL) return(0);
  765. GT_RefreshWindow(findwindow, NULL); 
  766.  
  767. SetWindowTitles(mgetWnd, "MGet window inactive--close daughter window to continue", (char *) ~0); 
  768. SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  769.  
  770. winsig = 1 << findwindow->UserPort->mp_SigBit;
  771.  
  772.  while (!done)
  773.     {
  774.     signals = Wait(winsig);
  775.     if (signals&winsig)
  776.         {
  777.         while ((!done) && (imsg = GT_GetIMsg(findwindow->UserPort)))
  778.             {
  779.             
  780.             switch(imsg->Class)
  781.                 {            
  782.                 case IDCMP_ACTIVEWINDOW:
  783.                     ActivateGadget(newgad,findwindow,NULL);
  784.                     break;
  785.                         
  786.                 case IDCMP_GADGETUP:
  787.                     strncpy(ss,((struct StringInfo*)newgad->SpecialInfo)->Buffer,sizeof(searchstring));
  788.                     done = 1;
  789.                     break;
  790.         
  791.                 case IDCMP_CLOSEWINDOW:
  792.                     done = 2;
  793.                     break;
  794.                     
  795.                 case IDCMP_REFRESHWINDOW:
  796.                     GT_BeginRefresh(findwindow);
  797.                     GT_EndRefresh(findwindow, TRUE);
  798.                     break;
  799.                 }
  800.             GT_ReplyIMsg(imsg);
  801.             }
  802.         }
  803.     }
  804.     
  805. CloseWindow(findwindow);
  806. FreeGadgets(findgadlist);
  807. FreeVisualInfo(findvi); 
  808. findwindow = NULL;
  809.  
  810. ClearPointer(mgetWnd);
  811.  
  812. if (linelengthrequest == 1) 
  813.     {
  814.     ChangeWindowTitle();    
  815.     return(atoi(ss));
  816.     }
  817. if ((done == 2)||(strlen(searchstring) == 0)) 
  818.     {
  819.     ChangeWindowTitle();
  820.     return(0);    /* can use searchstring now instead of ss */
  821.     }            /* because we're no longer worried about the nums */
  822.     
  823. /* Now find it in the filelist */
  824. search_current = (char *) filelist->lh_Head;
  825. if (SearchList(searchstring) == -1) DisplayBeep(Scr); else findgadgoto(index,3);
  826. return(1);
  827. }
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839. int mgetfindnext (VOID)
  840. {
  841. /* bump to next node */
  842. if (search_current == NULL) {DisplayBeep(Scr); return(0);}
  843. search_current = search_current->ln_Succ;
  844. if (search_current == NULL) {DisplayBeep(Scr); return(0);}
  845. index++;
  846. if (SearchList(searchstring) == -1) DisplayBeep(Scr); else findgadgoto(index,2);
  847. return(1);
  848. }
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860. int SearchList(char *key)
  861. {
  862. int found = 0;
  863. char sUpperBuffer[MAXFILELINELENGTH], sUppersearchstring[MAXFILELINELENGTH];
  864.  
  865. SetWindowTitles(mgetWnd, "Searching...", (char *) ~0); 
  866. SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  867.  
  868. if (casesensitive)    
  869.     {
  870.     while ((search_current != NULL)&&(found == 0))
  871.         {
  872.         if ((search_current->ln_Name != NULL)&&(strstr(search_current->ln_Name,searchstring) != 0))
  873.                 found = 1;
  874.                 else
  875.                 {
  876.                 search_current = search_current->ln_Succ; 
  877.                 index++;
  878.                 }
  879.         }
  880.     }
  881.     else
  882.     {
  883.     strncpy(sUppersearchstring,key,sizeof(sUppersearchstring));
  884.     UpperCase(sUppersearchstring);
  885.     while ((search_current != NULL)&&(found == 0))
  886.         {
  887.         if (search_current->ln_Name != NULL)
  888.             {
  889.             strncpy(sUpperBuffer,search_current->ln_Name,sizeof(sUpperBuffer)-1);
  890.             UpperCase(sUpperBuffer);
  891.             if (strstr(sUpperBuffer,sUppersearchstring) != 0)
  892.                 found = 1;
  893.             }
  894.         if (found == 0)
  895.             {
  896.             search_current = search_current->ln_Succ; 
  897.             index++;
  898.             }
  899.         }
  900.     }
  901.     
  902. ChangeWindowTitle();
  903. ClearPointer(mgetWnd);
  904.  
  905. if (found == 1) return(index); else return(-1);
  906. }
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918. void findgadgoto (int index, int numberofflashes)
  919. {
  920. int i, xmin, ymin, xmax, ymax, ystep, midscreen;
  921. int WindowHeightLines = nTopListHeight/nListFontSize;
  922.  
  923.  midscreen = index-(WindowHeightLines/2);
  924.  if (midscreen < 0) midscreen = 0;
  925.  
  926.  if (filelist_length > WindowHeightLines)
  927.          GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Top, midscreen, TAG_END);
  928.  
  929.  ystep = WindowHeightLines/2;            /* default, for middle of list */                                 
  930.  if ((filelist_length-index) < (WindowHeightLines/2))
  931.          ystep = index - (filelist_length - WindowHeightLines);
  932.  if ((index < (WindowHeightLines/2))||
  933.        (filelist_length <= WindowHeightLines)) ystep = index;    /* if at top */ 
  934.  
  935.  xmin = Scr->WBorLeft + 4;
  936.  ymin = (nTopListTop + (nListFontSize *ystep) + 2);
  937.  xmax = windowwidth - Scr->WBorLeft - 20;
  938.  ymax = ymin + nListFontSize - 1;
  939.  
  940.  SetDrMd(mgetWnd->RPort, 50); 
  941.  for (i=0;i<numberofflashes;i++)
  942.      {
  943.      RectFill(mgetWnd->RPort,xmin,ymin,xmax,ymax);
  944.      Delay(5);
  945.      RectFill(mgetWnd->RPort,xmin,ymin,xmax,ymax);
  946.      if (i<(numberofflashes-1)) Delay(5);
  947.      }
  948. }
  949.  
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958.  
  959.  
  960. int mgetnoparse (void)
  961. {
  962. if (noparse) 
  963.     {
  964.     noparse = 0; 
  965.     SetMenuValues();
  966.     }
  967.     else 
  968.     {
  969.     noparse = 1;        
  970.     SetMenuValues();
  971.     }
  972. }
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981. int mgetfiles (void)
  982. {
  983. if (filesflag) 
  984.     {
  985.     filesflag = 0;
  986.     getreadmes = 1;
  987.     SetMenuValues();     
  988.     }
  989.     else 
  990.     filesflag = 1;
  991. }
  992.  
  993.  
  994.  
  995.  
  996.  
  997.  
  998.  
  999. int mgetreadmes (void)
  1000. {
  1001. if (getreadmes) 
  1002.     {getreadmes = 0; 
  1003.      filesflag = 1;
  1004.      SetMenuValues();
  1005.     }
  1006.     else 
  1007.     getreadmes = 1;
  1008. }
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015. int mgetsplit (void)
  1016. {
  1017. if (nosplit) nosplit = 0; else nosplit = 1;
  1018. SetMenuValues();    
  1019. }
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026. int mgetlinelength (void)
  1027. {
  1028. int lin;
  1029.  
  1030. linelengthrequest = 1;        /* This is a HORRIBLE way to program, but I don't want  */
  1031. lin = mgetfind();            /* to try to change the parameters since it might screw */
  1032. linelengthrequest = 0;        /* up the mget_listview2 functions...                 */
  1033.  
  1034. if (lin >  0) maxoutputlinelength = lin;
  1035. }
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044. void PrintList(struct List *thislist)
  1045. {
  1046. struct Node *nodecurrent = thislist->lh_Head;
  1047.  
  1048. fprintf(fpOut,"thislist = %p\n",thislist);
  1049.  
  1050.  while (nodecurrent != NULL)
  1051.     {
  1052.     fprintf(fpOut,"[%s]\n",nodecurrent->ln_Name);
  1053.     nodecurrent = nodecurrent->ln_Succ;
  1054.     }
  1055.     
  1056. return();
  1057. }
  1058.  
  1059.  
  1060.  
  1061.  
  1062.  
  1063.  
  1064.  
  1065.  
  1066. int mgetopenfile (void)
  1067. {
  1068. FILE *test = NULL;
  1069.  
  1070.  memset(inputfile,NUL,sizeof(inputfile));
  1071.  
  1072.  SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  1073.  
  1074.  while (test == NULL) 
  1075.     {
  1076.     if (RequestAFile(inputfile) == 0) 
  1077.         {
  1078.         ClearPointer(mgetWnd);
  1079.         return(0);
  1080.         }
  1081.     test = fopen(inputfile,"r");
  1082.     }
  1083.  
  1084.  fclose(test);
  1085.  SetReqDefaults(inputfile);
  1086.  
  1087.  GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  1088.  FreeFileNodes(filelist); 
  1089.  FreeMem(filelist,sizeof(struct List));
  1090.  added_bytes -= sizeof(struct List);
  1091.  ClearPointer(mgetWnd);
  1092.  
  1093.  if (!(filelist = AllocMem(sizeof(struct List),MEMF_CLEAR)) )
  1094.     {
  1095.     MakeReq("mgetOpen : Couldn't create filelist!  Out of memory?\n",NULL,"Uh-oh");
  1096.     return(0);
  1097.     }
  1098.  added_bytes += sizeof(struct List);
  1099.         
  1100.  /* These are all dependant on a given filelist, so RESET! */
  1101.  filelist_length = 0;
  1102.  search_current = NULL;
  1103.  index = 0;
  1104.  
  1105.  NewList(filelist);      
  1106.  ReadmyFile();
  1107.  GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  1108.  
  1109.  
  1110. return(1);
  1111. }
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120. int mgetappend(void)
  1121. {
  1122. int returnme = 0;
  1123.  
  1124. memset(inputfile,NUL,sizeof(inputfile));
  1125.  
  1126. GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  1127. returnme = ReadmyFile();
  1128. GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  1129. return(returnme);
  1130. }
  1131.  
  1132.  
  1133.  
  1134.  
  1135.  
  1136.  
  1137. int mgetCloseWindow (void)
  1138. {
  1139. done=TRUE;
  1140. }
  1141.  
  1142.  
  1143.  
  1144.  
  1145.  
  1146.  
  1147.  
  1148.  
  1149.  
  1150. void SetMenuValues (void)
  1151. {
  1152. struct Menu *currentMenu = mgetMenus;
  1153. struct MenuItem *currentItem;
  1154.  
  1155.  if (currentMenu == NULL)
  1156.     {
  1157.     MakeReq("SetMenuValues:  error, mgetMenus is NULL!",NULL,"Huh?");
  1158.     return;
  1159.     }
  1160.     
  1161.  if (mgetWnd != NULL) ClearMenuStrip(mgetWnd);
  1162.  
  1163.  /* Make sure the CaseSensitive item in the second menu is checked correctly. */    
  1164.  currentMenu = currentMenu->NextMenu;
  1165.  if (currentMenu == NULL)
  1166.     {
  1167.     MakeReq("Malformed menu error 1",NULL,"Hmmm...");
  1168.     return;
  1169.     }
  1170.  
  1171.  currentItem = currentMenu->FirstItem;        /* #1 : Find */
  1172.  if (currentItem == NULL)
  1173.     {
  1174.     MakeReq("Malformed menu item error 1",NULL,"Hmmm...");
  1175.     return;
  1176.     }
  1177.  
  1178.  currentItem = currentItem->NextItem;        /* #2 : Next */
  1179.  if (currentItem == NULL)
  1180.     {
  1181.     MakeReq("Malformed menu item error 2",NULL,"Hmmm...");
  1182.     return;
  1183.     }
  1184.  currentItem = currentItem->NextItem;        /* #3 : Case Sensitive.  Bingo! */
  1185.  if (currentItem == NULL)
  1186.     {
  1187.     MakeReq("Malformed menu item error 3",NULL,"Hmmm...");
  1188.     return;
  1189.     }
  1190.  if (casesensitive)  currentItem->Flags |= CHECKED; 
  1191.             else  mgetNewMenu[9].nm_Flags &= ~(CHECKED);    
  1192.  
  1193.  /* now the toughie-- the Output menu. */
  1194.  currentMenu = currentMenu->NextMenu;
  1195.  if (currentMenu == NULL)
  1196.     {
  1197.     MakeReq("Malformed menu error 2",NULL,"Hmmm...");
  1198.     return;
  1199.     }
  1200.  currentItem = currentMenu->FirstItem;        /* #1: Aminet Parse */
  1201.  if (currentItem == NULL)
  1202.     {
  1203.     MakeReq("Malformed menu item error 4",NULL,"Hmmm...");
  1204.     return;
  1205.     }
  1206.  if (noparse) currentItem->Flags &= ~(CHECKED);
  1207.        else currentItem->Flags |= CHECKED;
  1208.        
  1209.        
  1210.  currentItem = currentItem->NextItem;        /* #2: Get Files */
  1211.  if (currentItem == NULL)
  1212.     {
  1213.     MakeReq("Malformed menu item error 5",NULL,"Hmmm...");
  1214.     return;
  1215.     }
  1216.  if (noparse) currentItem->Flags &= ~(ITEMENABLED);
  1217.        else currentItem->Flags |= ITEMENABLED;
  1218.  if (filesflag) currentItem->Flags |= CHECKED;
  1219.           else currentItem->Flags &= ~(CHECKED);
  1220.           
  1221.  currentItem = currentItem->NextItem;        /* #3: Get Readmes */
  1222.  if (currentItem == NULL)
  1223.     {
  1224.     MakeReq("Malformed menu item error 6",NULL,"Hmmm...");
  1225.     return;
  1226.     }
  1227.  if (noparse) currentItem->Flags &= ~(ITEMENABLED);
  1228.        else currentItem->Flags |= ITEMENABLED;
  1229.  if (getreadmes) currentItem->Flags |= CHECKED;
  1230.            else currentItem->Flags &= ~(CHECKED);
  1231.     
  1232.  currentItem = currentItem->NextItem;        /* #4: Split Commands */
  1233.  if (currentItem == NULL)
  1234.     {
  1235.     MakeReq("Malformed menu item error 7",NULL,"Hmmm...");
  1236.     return;
  1237.     }
  1238.  if (noparse) currentItem->Flags &= ~(ITEMENABLED);
  1239.        else currentItem->Flags |= ITEMENABLED;
  1240.  if (nosplit) currentItem->Flags &= ~(CHECKED);
  1241.            else currentItem->Flags |= CHECKED;
  1242.            
  1243.  
  1244.  currentItem = currentItem->NextItem;        /* #5: Use CD's */
  1245.  if (currentItem == NULL)
  1246.     {
  1247.     MakeReq("Malformed menu item error 8",NULL,"Hmmm...");
  1248.     return;
  1249.     }
  1250.  if (noparse) currentItem->Flags &= ~(ITEMENABLED);
  1251.        else currentItem->Flags |= ITEMENABLED;
  1252.  if (simplepaths) currentItem->Flags |= CHECKED;
  1253.            else currentItem->Flags &= ~(CHECKED);
  1254.            
  1255.  currentItem = currentItem->NextItem;        /* #6: Line length */
  1256.  if (currentItem == NULL)
  1257.     {
  1258.     MakeReq("Malformed menu item error 9",NULL,"Hmmm...");
  1259.     return;
  1260.     }
  1261.  if ((noparse)||(nosplit)) currentItem->Flags &= ~(ITEMENABLED);
  1262.        else currentItem->Flags |= ITEMENABLED;
  1263.  
  1264.  ResetMenuStrip( mgetWnd, mgetMenus );
  1265.                         
  1266. }
  1267.  
  1268.  
  1269.  
  1270.  
  1271.  
  1272.  
  1273. /* Turns all \n's in input string into <space><newline>'s */
  1274. void FindReturns(char *mystring)
  1275. {
  1276. char *thischar=mystring, *prevchar=mystring;
  1277.  
  1278.  while (*thischar != NULL)
  1279.     {
  1280.     
  1281.     if ( (*prevchar  ==   92) &&                        /* any '/'s ? */
  1282.          ((*thischar ==   78)||(*thischar == 110)) &&      /* N's or n's */
  1283.          (prevchar   !=  NULL) &&                        /* Sanity chk */
  1284.          (thischar   !=  NULL))
  1285.         
  1286.         {
  1287.         *prevchar = 32;   /* set this to a space--easier than shortening string */
  1288.         *thischar = 10;   /* and end this line with a newline char */
  1289.         }
  1290.     
  1291.     prevchar = thischar;
  1292.     thischar++;
  1293.     }
  1294. }
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304. int AddFile(struct List *mylist, char *newstring)
  1305. {
  1306. struct Node *newnode;
  1307. char *newname, *i, returnchar = 10, spacechar = 32;
  1308. UBYTE diff=MAXFILELINELENGTH;
  1309. int minlinelength = 1;
  1310.  
  1311.  if (keepblanklines == 1) minlinelength = 0;
  1312.  if (newstring == NULL) return(0);
  1313.  if (strlen(newstring) < minlinelength) return(0); 
  1314.  
  1315.  if (!( newnode = AllocMem(sizeof(struct Node),MEMF_CLEAR) ))
  1316.     {
  1317.     MakeReq("AddFile: Couldn't allocate Memory for Node!",NULL,"Uh-oh");
  1318.     return(0);
  1319.     }
  1320.  added_bytes += sizeof(struct Node);
  1321.     
  1322.  i = strchr(newstring, (char) returnchar);
  1323.  if (i != NULL) diff = i-newstring;  /* number of chars into the string where newline is! */
  1324.  
  1325.  if (!( newname = AllocMem(diff+1,MEMF_CLEAR) ))
  1326.     {
  1327.     MakeReq("AddFile: Couldn't allocate memory for Node String!",NULL,"D-oh!");
  1328.     return(0);
  1329.     }
  1330.   added_bytes += diff+1;
  1331.     
  1332. strncpy(newname,newstring,diff);   /* copy over the bytes */
  1333.  
  1334. newnode->ln_Pri = diff - 126;        /* store string length in unused field */
  1335.                             /* really bad style, isn't it? */
  1336.  
  1337. newnode->ln_Name=newname;          /* and set ze pointer! */
  1338.  
  1339. AddTail(mylist, newnode);
  1340. return(1);
  1341. }
  1342.  
  1343.  
  1344.  
  1345. /* Prints out a file.  Makes sure there is a \r\n after the end of every line */
  1346. int PrintFile(char *szFileName, int PrintReturnFirst)
  1347. {
  1348.     FILE *input_file = fopen(szFileName,"r");
  1349.     char inputline[MAXFILELINELENGTH], *a, *b;
  1350.     int nLen;
  1351.  
  1352.      if (input_file == NULL) 
  1353.      {
  1354.         return(0);
  1355.      }
  1356.  
  1357.      if (PrintReturnFirst == 1)
  1358.      {
  1359.          fprintf(fpOut,"\r\n");
  1360.          
  1361.      }
  1362.          
  1363.     /* Read until we get a line-end */
  1364.     while(!feof(input_file))
  1365.     {
  1366.         memset(inputline,NUL,MAXFILELINELENGTH);
  1367.         fgets(inputline,MAXFILELINELENGTH,input_file);  /* Read up to MAXFILELINELENGTH chars from inputfile */
  1368.         
  1369.         nLen = strlen(inputline);
  1370.         
  1371.         if (nLen >= 2)
  1372.         {
  1373.             /* make sure that it ends in a \r\n */
  1374.             a = &inputline[strlen(inputline)-2];
  1375.             b = &inputline[strlen(inputline)-1];
  1376.             
  1377.             if ((*a == '\r')&&(*b == '\n')) /* the easy case */
  1378.             {
  1379.                 fprintf(fpOut,"%s",inputline);
  1380.             }
  1381.             else
  1382.             {
  1383.                 if ((*a != '\r')&&(*b == '\n'))  /* the normal case, for Amigas */
  1384.                 {
  1385.                 /* make the newline a return, and then append a newline */
  1386.                     *b = '\r';
  1387.                     fprintf(fpOut,"%s\n",inputline);
  1388.                 }
  1389.                 else
  1390.                 {
  1391.                 if ((*a == '\r')&&(*b != '\n'))    /* the abnormal case */
  1392.                     {
  1393.                         *b = '\n';
  1394.                         fprintf(fpOut,"%s",inputline);
  1395.                     }
  1396.                     else
  1397.                     {
  1398.                         /* *a != \r, *b != \n */
  1399.                         fprintf(fpOut,"%s\r\n",inputline);
  1400.                     }
  1401.                 }
  1402.             }
  1403.         }
  1404.         else
  1405.         if (nLen == 1) fprintf(fpOut,"\r\n");
  1406.     }    
  1407.     fclose(input_file);
  1408.     return(1);
  1409. }
  1410.  
  1411.  
  1412.  
  1413. /* returns the number of lines successfully parsed and added to the list */
  1414. int ReadmyFile(void)
  1415. {
  1416. FILE *input_file = NULL;
  1417. char inputline[MAXFILELINELENGTH];
  1418. char *firstnull;
  1419. int nullpos = 0, okline = 0, nUpdate = 50;
  1420. int filelength = 0, failed_lines = 0;
  1421. int minlinelength = 1;
  1422.  
  1423. if (keepblanklines == 1) minlinelength = 0;
  1424.  
  1425. SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  1426.  
  1427.  while (input_file == NULL) 
  1428.     {
  1429.     input_file = fopen(inputfile,"r");
  1430.     if ((input_file == NULL)&&(RequestAFile(inputfile) == 0)) 
  1431.         {
  1432.         ClearPointer(mgetWnd);
  1433.         return(0);
  1434.         }
  1435.     }
  1436.     
  1437.  SetReqDefaults(inputfile);
  1438.  
  1439.  while (!feof(input_file))
  1440.     {
  1441.     filelength++;        
  1442.     okline=0;  
  1443.     /* Read until we get a line-end */
  1444.     while((okline==0)&&(!feof(input_file)))
  1445.         {
  1446.         memset(inputline,NUL,MAXFILELINELENGTH);
  1447.         fgets(inputline,MAXFILELINELENGTH,input_file);  /* Read up to MAXFILELINELENGTH chars from inputfile */
  1448.         firstnull = strchr(inputline,(char) 10); /* Find address of carriage return */
  1449.         nullpos = firstnull - inputline;           /* Subtract to get return pos */
  1450.         if ((nullpos >= minlinelength)&&(nullpos < MAXFILELINELENGTH)) okline=1;
  1451.         }
  1452.     
  1453.     if ((nullpos < MAXFILELINELENGTH)||(noparse))
  1454.           {
  1455.               if (AddFile(filelist, inputline) == 1)
  1456.               {
  1457.                   filelist_length++;
  1458.  
  1459.                     if (nUpdate == 0)
  1460.                     {
  1461.                         sprintf(windowtitle,"Loading: %i",filelist_length);   
  1462.                         SetWindowTitles(mgetWnd, windowtitle , (char *) ~0);                   
  1463.                         nUpdate = 50;
  1464.                     }
  1465.                     else
  1466.                     {
  1467.                         nUpdate--;
  1468.                     }
  1469.                  }
  1470.               else
  1471.               {
  1472.                   failed_lines++;
  1473.               }
  1474.           }
  1475.           else
  1476.           {
  1477.               failed_lines++;
  1478.           }
  1479.               
  1480.     }
  1481.  
  1482. fclose(input_file);
  1483. ClearPointer(mgetWnd);    
  1484. return(filelist_length);
  1485. }
  1486.  
  1487.  
  1488.  
  1489.  
  1490.  
  1491.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498. VOID FreeFileNodes(struct List *mylist)
  1499. {
  1500. struct Node *nextnode,*worknode = mylist->lh_Head;  
  1501. int nodesize = sizeof(struct Node);
  1502.  
  1503.  while (nextnode = (worknode->ln_Succ))
  1504.     {
  1505.     if (worknode->ln_Name != NULL)
  1506.         {
  1507.         FreeMem(worknode->ln_Name,worknode->ln_Pri+127);
  1508.         added_bytes -= worknode->ln_Pri+127;
  1509.         }        
  1510.     FreeMem(worknode,nodesize);
  1511.     worknode = nextnode;
  1512.     added_bytes -= nodesize;
  1513.     }
  1514. }
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.  
  1525.  
  1526. void ChangeWindowTitle(void)
  1527. {
  1528. char *fstring = inputfile, *f2;
  1529. char sSubString[60];
  1530. int charlength = (windowwidth-81)/8 - 40;
  1531.  
  1532. if (charlength <= 0) 
  1533.     {
  1534.     fstring = sSubString;
  1535.     fstring[0] = NUL;
  1536.     }
  1537.     else
  1538.     if (strlen(fstring) > charlength)
  1539.         {
  1540.         f2 = inputfile + strlen(inputfile) - charlength - 1;    
  1541.         if (f2 > inputfile)
  1542.             {
  1543.             fstring = sSubString;
  1544.             strcpy(fstring,f2);
  1545.             }
  1546.         }    
  1547. sprintf(windowtitle,"(%s) %i files, %u kilobytes selected.",fstring, files_selected, kbytes_selected);   
  1548. SetWindowTitles(mgetWnd, windowtitle , (char *) ~0); 
  1549. return();
  1550. }
  1551.  
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557.  
  1558.  
  1559.  
  1560.  
  1561.  
  1562. VOID UpdateByteCount(char *mystring, int addorsub)
  1563. {
  1564. int multiplier = INVALID;
  1565. int filesize = 0, wholenum;
  1566. int outputlength = -1;
  1567.  
  1568. if (mystring == NULL) {return();}
  1569. if (mystring[35] == 'M') multiplier = 1024;   /* 1024 k in a M */
  1570. if (mystring[35] == 'K') multiplier = 1;     /* 1 k in a k */
  1571. if (mystring[35] == '?') multiplier = 0;
  1572. if (multiplier == INVALID) {return();}    /* If we don't know M or K, abort */
  1573.  
  1574.  if (mystring[33] == '.')
  1575.     {
  1576.     /* figure out kilobytes */
  1577.     wholenum = (int) (mystring[32] - 48);
  1578.     
  1579.     if ((wholenum >= 0)&&(wholenum <= 9))
  1580.         {
  1581.         filesize = filesize + (multiplier * wholenum);
  1582.         }
  1583.     wholenum = (int) (mystring[34] - 48);
  1584.     if ((wholenum >= 0)&&(wholenum <= 9))
  1585.         {
  1586.         filesize = filesize + ((multiplier/10) * wholenum);
  1587.         }
  1588.     }
  1589.     else
  1590.     {
  1591.     wholenum = (int) (mystring[32] - 48);
  1592.     if ((wholenum >= 0)&&(wholenum <= 9))
  1593.         {
  1594.         filesize = filesize + (100 * multiplier * wholenum);
  1595.         }        
  1596.     wholenum = (int) (mystring[33] - 48);
  1597.         if ((wholenum >= 0)&&(wholenum <= 9))
  1598.         {
  1599.         filesize = filesize + ( 10 * multiplier * wholenum);
  1600.         }
  1601.     wholenum = (int) (mystring[34] - 48);
  1602.     if ((wholenum >= 0)&&(wholenum <= 9))
  1603.         {
  1604.         filesize = filesize + (  1 * multiplier * wholenum);
  1605.         }
  1606.     }    
  1607. kbytes_selected = kbytes_selected + (filesize * addorsub);
  1608. return();
  1609. }
  1610.  
  1611.  
  1612.  
  1613.  
  1614.  
  1615.  
  1616.  
  1617.  
  1618.  
  1619.  
  1620.  
  1621. VOID Cleanup(void)
  1622. {
  1623.  
  1624. if ((fpOut != stdout)&&(fpOut != NULL)) fclose(fpOut);
  1625.  
  1626. if (listfontdata)  CloseFont(listfontdata);
  1627. if (windowisopen)  ClosemgetWindow();
  1628. if (screenisopen)  CloseDownScreen();
  1629. if (filelist)        
  1630.                 {
  1631.                 FreeFileNodes(filelist); 
  1632.                 FreeMem(filelist,sizeof(struct List));
  1633.                 added_bytes -= sizeof(struct List);
  1634.                }
  1635. if (getlist) 
  1636.               {
  1637.                 FreeFileNodes(getlist);
  1638.                 FreeMem(getlist,sizeof(struct List));
  1639.                 added_bytes -= sizeof(struct List);
  1640.                }
  1641. if (WorkbenchBase) CloseLibrary((struct Library *)WorkbenchBase);
  1642. if (IconBase)         CloseLibrary((struct Library *)IconBase);
  1643. if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  1644. if (AslBase)        CloseLibrary((struct Library *)AslBase);
  1645. if (UtilityBase)   CloseLibrary((struct Library *)UtilityBase);
  1646. if (GraphicsBase)  CloseLibrary((struct GraphicsLib *)GraphicsBase);
  1647. if (GadToolsBase)  CloseLibrary((struct Library *)GadToolsBase);
  1648. return();
  1649. }
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.  
  1657.  
  1658.  
  1659.  
  1660.  
  1661. int RequestAFile(char *szBuffer)
  1662. {
  1663. int rvalue = 1;
  1664.  
  1665. if (strlen(defDir) == 0) strcpy(defDir,"ram:");
  1666. if (strlen(defFile)== 0) strcpy(defFile,"RECENT");
  1667.  
  1668. struct TagItem frtags[] =
  1669. {
  1670.     ASL_Hail,        (ULONG)"Select a text file to browse.",
  1671.     ASL_Height,    350,
  1672.     ASL_Width,    320,
  1673.     ASL_LeftEdge,    50,
  1674.     ASL_TopEdge,    35,
  1675.     ASL_OKText,    (ULONG)"Okay",
  1676.     ASL_CancelText,(ULONG)"Cancel",
  1677.     ASL_File,        defFile,
  1678.     ASL_Dir,         defDir,
  1679.     ASL_Window,    mgetWnd,
  1680.     TAG_DONE
  1681. };
  1682.  
  1683. struct FileRequester *fr;
  1684.  
  1685. fr = (struct FileRequester *) AllocAslRequest(ASL_FileRequest, frtags);
  1686.  
  1687. if (fr == NULL) 
  1688.     {
  1689.     rvalue = 0 ;
  1690.     }
  1691.  
  1692.  if ((rvalue)&&(AslRequest(fr, NULL)))
  1693.     {
  1694.     strcpy(szBuffer,fr->rf_Dir);
  1695.     strncpy(defDir,fr->rf_Dir,sizeof(defDir));
  1696.     strncpy(defFile,fr->rf_File,sizeof(defFile));
  1697.     if ((defDir[strlen(defDir)-1] != '/')&&
  1698.         (defDir[strlen(defDir)-1] != ':')) strcat(szBuffer,"/");
  1699.     strcat(szBuffer,fr->rf_File);
  1700.     }
  1701.     else
  1702.     rvalue = 0;
  1703.     
  1704. if (fr != NULL) FreeAslRequest(fr);
  1705.  
  1706. return(rvalue);
  1707. }
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717. void TurnOnAllMenuItems(struct Menu *myMenu)
  1718. {
  1719. struct MenuItem *mItem;
  1720.  
  1721.  while (myMenu != NULL)
  1722.     {
  1723.     mItem = myMenu->FirstItem;
  1724.     while (mItem != NULL)
  1725.         {
  1726.         mItem->Flags |= ITEMENABLED;
  1727.         mItem = mItem->NextItem;
  1728.         }
  1729.     myMenu = myMenu->NextMenu;
  1730.     }
  1731. return;
  1732. }
  1733.  
  1734.  
  1735.  
  1736.  
  1737.  
  1738.  
  1739.  
  1740.  
  1741.  
  1742.  
  1743. VOID SetReqDefaults(char *szFilePath)
  1744. {
  1745. char *sFileStart;
  1746.  
  1747.  sFileStart = strrchr(szFilePath,'/');
  1748.  if (sFileStart == NULL)
  1749.      {
  1750.      sFileStart = strrchr(szFilePath,':');
  1751.      if (sFileStart == NULL)
  1752.          {
  1753.          sFileStart = szFilePath;
  1754.          }
  1755.      }
  1756.  
  1757.  if (sFileStart != NULL) strncpy(defFile,sFileStart+(sFileStart != szFilePath),sizeof(defFile));
  1758.  if ((sFileStart != NULL)&&(sFileStart != szFilePath)) strncpy(defDir,szFilePath,(sFileStart - szFilePath) + 1);
  1759.  return();
  1760. }
  1761.  
  1762.  
  1763.  
  1764.  
  1765.  
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772. VOID UpperCase(char *sOldString)
  1773. {
  1774. char *i = sOldString;
  1775. int diff = 'a' - 'A';
  1776.  
  1777.  if (sOldString == NULL) return();
  1778.  
  1779.  while (*i != '\0')
  1780.     {
  1781.     if ((*i >= 'a')&&(*i <= 'z')) *i = *i - diff;
  1782.     i++;
  1783.     }
  1784.  
  1785. return();
  1786. }
  1787.  
  1788.  
  1789. VOID LowerCase(char *sOldString)
  1790. {
  1791. char *i = sOldString;
  1792. int diff = 'a' - 'A';
  1793.  
  1794.  if (sOldString == NULL) return();
  1795.  
  1796.  while (*i != '\0')
  1797.     {
  1798.     if ((*i >= 'A')&&(*i <= 'Z')) *i = *i + diff;
  1799.     i++;
  1800.     }
  1801.  
  1802. return();
  1803. }
  1804.  
  1805.  
  1806.  
  1807.  
  1808.  
  1809.  
  1810.  
  1811.  
  1812. VOID ParseCliArgs(int argc, char *argv[])
  1813. {
  1814.  int nextpasslookfor = 0;
  1815.  FILE *fpTemp = NULL;
  1816.  
  1817.  memset(defDir,NUL,sizeof(defDir));
  1818.  memset(defFile,NUL,sizeof(defFile));
  1819.  memset(szHeaderFile,NUL,sizeof(szHeaderFile));
  1820.  memset(szFooterFile,NUL,sizeof(szFooterFile));
  1821.  memset(inputfile,NUL,sizeof(inputfile));
  1822.  
  1823.  if (argc > 1) 
  1824.      {
  1825.      strncpy(inputfile,argv[1],sizeof(inputfile));
  1826.      SetReqDefaults(inputfile);
  1827.      }
  1828.          
  1829.  if (*inputfile == '?')
  1830.     {
  1831.     fprintf(fpOut,"%s",template);
  1832.     Cleanup();
  1833.     exit(0);
  1834.     }
  1835.  
  1836.  
  1837.  for (int i=2; i<=argc; i++)
  1838.     {
  1839.     if (nextpasslookfor == 2)
  1840.         {
  1841.         strncpy(szPubScreenName,argv[i-1],sizeof(szPubScreenName));
  1842.         pubscreenname = szPubScreenName;
  1843.         screentype = USE_PUBSCREEN;
  1844.         continue;            /* skip to next loop */
  1845.         }
  1846.    if (nextpasslookfor == 7)         /* FILE PARAMETER */
  1847.          {
  1848.          strncpy(inputfile,argv[i-1],sizeof(inputfile));
  1849.          SetReqDefaults(inputfile);
  1850.          }
  1851.     if (nextpasslookfor == 9)        /* COMMAND PARAMETER */
  1852.         {
  1853.         strncpy(szCommandString,argv[i-1],sizeof(szCommandString));
  1854.         }
  1855.     
  1856.     UpperCase(argv[i-1]);
  1857.  
  1858.     switch(nextpasslookfor)
  1859.     {    
  1860.     case(1):
  1861.         if (atoi(argv[i-1]) > 0)  maxoutputlinelength = atoi(argv[i-1]);
  1862.         break;
  1863.         
  1864.     /* case 2 is up above, before the Upper() command */
  1865.     
  1866.     case(3):        /* WIDTH PARAMETER */
  1867.         if (atoi(argv[i-1]) > 0)  windowwidth = 155;    /* min level */
  1868.         if (atoi(argv[i-1]) > 155) windowwidth = atoi(argv[i-1]);
  1869.         break;
  1870.     case(4):        /* HEIGHT PARAMETER */
  1871.         if (atoi(argv[i-1]) > 0) windowheight = 167;    /* min level */
  1872.         if (atoi(argv[i-1]) > 167) windowheight = atoi(argv[i-1]);
  1873.         break;
  1874.     case(5):        /* TOP PARAMETER */
  1875.         if (atoi(argv[i-1]) > 0) windowtop = atoi(argv[i-1]);
  1876.         break;
  1877.     case(6):        /* LEFT PARAMETER */
  1878.         if (atoi(argv[i-1]) > 0) windowleft = atoi(argv[i-1]);
  1879.         break;
  1880.         
  1881.     /* Case 7 is up above, before the Upper() command */
  1882.     
  1883.     case(8):        /* OUTPUT PARAMETER */
  1884.         fpTemp = fopen(argv[i-1],"w");
  1885.         if (fpTemp != NULL) fpOut = fpTemp;
  1886.         break;
  1887.     
  1888.     /* Case 9 is up above, before the Upper() command */
  1889.     
  1890.     case(10):        /* HEADER PARAMETER */
  1891.         strncpy(szHeaderFile,argv[i-1],sizeof(szHeaderFile));
  1892.         break;
  1893.         
  1894.     case(11):        /* FOOTER PARAMETER */
  1895.         strncpy(szFooterFile,argv[i-1],sizeof(szFooterFile));
  1896.         break;
  1897.  
  1898.     case(12):        /* FONT PARAMETER */
  1899.         strncpy(sListFontName,argv[i-1],sizeof(sListFontName));
  1900.         LowerCase(sListFontName);
  1901.         if (strstr(sListFontName,".font") == NULL) strncat(sListFontName,".font",sizeof(sListFontName));
  1902.         break;
  1903.         
  1904.     case(13):        /* FONTSIZE PARAMETER */
  1905.         if (atoi(argv[i-1]) > 0) nListFontSize = atoi(argv[i-1]);
  1906.         break;
  1907.         
  1908.     default:
  1909.         /* nothing */
  1910.         break;        
  1911.     }
  1912.     nextpasslookfor = 0;
  1913.     
  1914.     
  1915.     
  1916.     if (strcmp(argv[i-1],"NOAPPWINDOW") == 0) appwindow         = 0;
  1917.     if (strcmp(argv[i-1],"CASESENSITIVE") == 0) casesensitive= 1;    
  1918.     if (strcmp(argv[i-1],"NOPARSE") == 0)         noparse             = 1;
  1919.     if (strcmp(argv[i-1],"NOCOMMAND") == 0)     nocommand        = 1;
  1920.     if (strcmp(argv[i-1],"NOSPLIT") == 0)         nosplit             = 1;
  1921.     if (strcmp(argv[i-1],"GETREADMES") == 0)     getreadmes         = 1;    
  1922.     if (strcmp(argv[i-1],"NOCD") == 0)            nocd                = 1;
  1923.    if (strcmp(argv[i-1],"NOFILES") == 0)     
  1924.                                             {
  1925.                                             filesflag     = 0;
  1926.                                             getreadmes  = 1;
  1927.                                             }
  1928.      if (strcmp(argv[i-1],"LINELENGTH") == 0)        nextpasslookfor= 1;
  1929.      if (strcmp(argv[i-1],"PUBSCREEN") == 0)        nextpasslookfor= 2;
  1930.     if (strcmp(argv[i-1],"DEFPUBSCREEN") == 0)       screentype = USE_PUBSCREEN;     
  1931.     if ((strcmp(argv[i-1],"WBSCREEN") == 0)||
  1932.         (strcmp(argv[i-1],"WORKBENCHSCREEN") == 0)) screentype = USE_WBSCREEN;
  1933.     if (strcmp(argv[i-1],"NOSIMPLEPATHS") == 0)       simplepaths  = 0;    
  1934.     if (strcmp(argv[i-1],"KEEPBLANKLINES") == 0) keepblanklines = 1;
  1935.                                                             
  1936.     if (strcmp(argv[i-1],"WIDTH") == 0)            nextpasslookfor = 3;
  1937.     if (strcmp(argv[i-1],"HEIGHT") == 0)        nextpasslookfor = 4;
  1938.     if (strcmp(argv[i-1],"TOP") == 0)            nextpasslookfor = 5;
  1939.     if (strcmp(argv[i-1],"LEFT") == 0)            nextpasslookfor = 6;
  1940.     if (strcmp(argv[i-1],"FILE") == 0)            nextpasslookfor = 7;
  1941.     if (strcmp(argv[i-1],"OUTPUT") == 0)        nextpasslookfor = 8;
  1942.     if (strcmp(argv[i-1],"COMMAND") == 0)        nextpasslookfor = 9;
  1943.     if (strcmp(argv[i-1],"HEADER") == 0)        nextpasslookfor = 10;
  1944.     if (strcmp(argv[i-1],"FOOTER") == 0)        nextpasslookfor = 11;
  1945.     if (strcmp(argv[i-1],"FONT") == 0)        nextpasslookfor = 12;
  1946.     if (strcmp(argv[i-1],"FONTSIZE") == 0)    nextpasslookfor = 13;
  1947.     if (strcmp(argv[i-1],"SIZE") == 0)        nextpasslookfor = 13;
  1948.     }
  1949.  
  1950.     return();
  1951. }
  1952.  
  1953.  
  1954.  
  1955.  
  1956.  
  1957.  
  1958.  
  1959.  
  1960.  
  1961.  
  1962. VOID wbmain(struct WBStartup *argv)
  1963. {
  1964. BStartedFromWB = TRUE;
  1965. IconBase = OpenLibrary("icon.library",33);
  1966. if (IconBase == NULL)
  1967.      {
  1968.      exit(2);
  1969.      }
  1970. ParseWBArgs(argv);
  1971. main(0,argv);
  1972. }
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981. VOID ParseWBArgs(struct WBStartup *argv)
  1982. {
  1983. struct WBArg *wb_arg = argv->sm_ArgList;
  1984. struct DiskObject *dobj;
  1985. char **toolarray, *sTemp;
  1986. FILE *fpTemp = NULL;
  1987.  
  1988.  
  1989. memset(defDir,NUL,sizeof(defDir));
  1990. memset(defFile,NUL,sizeof(defFile));
  1991. memset(szHeaderFile,NUL,sizeof(szHeaderFile));
  1992. memset(szFooterFile,NUL,sizeof(szFooterFile));
  1993.  
  1994.  
  1995. /* Parse the tooltypes from the program file */
  1996. dobj = GetDiskObject(wb_arg->wa_Name);
  1997.  
  1998. if (dobj != NULL)
  1999.  {
  2000.      toolarray = (char **) dobj->do_ToolTypes;
  2001.     if (toolarray != NULL)
  2002.     {
  2003.     
  2004.         if (sTemp = (char *) FindToolType(toolarray,"OUTPUT")) 
  2005.                                             {
  2006.                                             fpTemp = fopen(sTemp,"w");
  2007.                                             if (fpTemp != NULL) fpOut = fpTemp;
  2008.                                             
  2009.                                             /* put a COULDN'T OPEN OUTPUT FILE req here !*/
  2010.                                             
  2011.                                             }
  2012.         if (sTemp = (char *) FindToolType(toolarray,"FILE")) 
  2013.                 {
  2014.                 strncpy(inputfile,sTemp,sizeof(inputfile));
  2015.                 SetReqDefaults(inputfile);
  2016.                 }
  2017.         if (sTemp = (char *) FindToolType(toolarray,"NOPARSE"))       noparse     = 1;
  2018.         if (sTemp = (char *) FindToolType(toolarray,"NOCOMMAND"))      nocommand   = 1;
  2019.        if (sTemp = (char *) FindToolType(toolarray,"NOSPLIT"))       nosplit     = 1;    
  2020.        if (sTemp = (char *) FindToolType(toolarray,"GETREADMES"))  getreadmes  = 1;
  2021.         if (sTemp = (char *) FindToolType(toolarray,"NOFILES"))
  2022.                                                              {
  2023.                                                             filesflag     = 0;
  2024.                                                             getreadmes  = 1;
  2025.                                                             }
  2026.        if (sTemp = (char *) FindToolType(toolarray,"LINELENGTH"))
  2027.                    {
  2028.                    if (atoi(sTemp) > 0)  maxoutputlinelength = atoi(sTemp); 
  2029.                    }
  2030.                   
  2031.           if (sTemp = (char *) FindToolType(toolarray,"PUBSCREEN"))   
  2032.                       {
  2033.                       strcpy(szPubScreenName,sTemp);
  2034.                       pubscreenname = szPubScreenName;
  2035.                       screentype = USE_PUBSCREEN;
  2036.                       }
  2037.           
  2038.           if (sTemp = (char *) FindToolType(toolarray,"NOSIMPLEPATHS"))     simplepaths = 0;        
  2039.           if (sTemp = (char *) FindToolType(toolarray,"NOPARSE"))   noparse = 1;        
  2040.         if (sTemp = (char *) FindToolType(toolarray,"NOAPPWINDOW")) appwindow = 0;
  2041.         if (sTemp = (char *) FindToolType(toolarray,"WBSCREEN"))           screentype = USE_WBSCREEN;
  2042.         if (sTemp = (char *) FindToolType(toolarray,"WORKBENCHSCREEN")) screentype = USE_WBSCREEN;                                
  2043.         if (sTemp = (char *) FindToolType(toolarray,"NOCD"))                 nocd = 1;
  2044.         if (sTemp = (char *) FindToolType(toolarray,"KEEPBLANKLINES")) keepblanklines = 1;
  2045.         
  2046.         if (sTemp = (char *) FindToolType(toolarray,"WIDTH"))                             
  2047.                         {
  2048.                         if (atoi(sTemp) > 0)  windowwidth = 155;    /* min level */
  2049.                         if (atoi(sTemp) > 155) windowwidth = atoi(sTemp);
  2050.                         }
  2051.         if (sTemp = (char *) FindToolType(toolarray,"HEIGHT"))     
  2052.                         {                        
  2053.                         if (atoi(sTemp) > 0) windowheight = 167;    /* min level */
  2054.                         if (atoi(sTemp) > 167) windowheight = atoi(sTemp);
  2055.                         }
  2056.         if (sTemp = (char *) FindToolType(toolarray,"TOP"))                             
  2057.                         {
  2058.                         if (atoi(sTemp) > 0) windowtop = atoi(sTemp);
  2059.                         }
  2060.         if (sTemp = (char *) FindToolType(toolarray,"LEFT"))                             
  2061.                         {
  2062.                         if (atoi(sTemp) > 0) windowleft = atoi(sTemp);
  2063.                         }                    
  2064.         if (sTemp = (char *) FindToolType(toolarray,"CASESENSITIVE"))                             
  2065.                         {
  2066.                         casesensitive = 1;
  2067.                         }
  2068.         if (sTemp = (char *) FindToolType(toolarray,"COMMAND"))
  2069.                         {
  2070.                         strncpy(szCommandString,sTemp,sizeof(szCommandString));
  2071.                         }
  2072.         if (sTemp = (char *) FindToolType(toolarray,"HEADER"))
  2073.                         {
  2074.                         strncpy(szHeaderFile,sTemp,sizeof(szHeaderFile));
  2075.                         }
  2076.         if (sTemp = (char *) FindToolType(toolarray,"FOOTER"))
  2077.                         {
  2078.                         strncpy(szFooterFile,sTemp,sizeof(szFooterFile));
  2079.                         }
  2080.         if (sTemp = (char *) FindToolType(toolarray,"FONT"))
  2081.                         {
  2082.                         strncpy(sListFontName,sTemp,sizeof(sListFontName));
  2083.                         LowerCase(sListFontName);
  2084.                         if (strstr(sListFontName,".font") == NULL) strncat(sListFontName,".font",sizeof(sListFontName));
  2085.                         }
  2086.         if (sTemp = (char *) FindToolType(toolarray,"FONTSIZE"))
  2087.                         {
  2088.                         if (atoi(sTemp) > 0) nListFontSize = atoi(sTemp);
  2089.                         }
  2090.         if (sTemp = (char *) FindToolType(toolarray,"SIZE"))
  2091.                         {
  2092.                         if (atoi(sTemp) > 0) nListFontSize = atoi(sTemp);
  2093.                         }
  2094.     }                     
  2095.  FreeDiskObject(dobj);
  2096.  }
  2097.  
  2098.  /* Get the name of the file extended_clicked, if there is one */
  2099.  if (argv->sm_NumArgs > 1) 
  2100.     {
  2101.     wb_arg++;    /* The first name is the programs name, the 2nd is the proj. icon */
  2102.     if (wb_arg->wa_Name != NULL) 
  2103.         {
  2104.         strncpy(inputfile,wb_arg->wa_Name,sizeof(inputfile));
  2105.         CurrentDir(wb_arg->wa_Lock);
  2106.         }
  2107.     }
  2108.     
  2109. return();
  2110. }
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  
  2117.  
  2118.  
  2119.  
  2120.  
  2121. /********/
  2122. /* MAIN */
  2123. /********/
  2124. VOID main(int argc, char *argv[])
  2125. {
  2126. FILE *test = NULL, *fpTemp = NULL;
  2127. ULONG winsig,signals;
  2128. BPTR olddir;
  2129.  
  2130. GraphicsBase = OpenLibrary("graphics.library",37);
  2131.  if (GraphicsBase==NULL)
  2132.     {
  2133.     fprintf(fpOut,"couldn't open Graphics.library v37!");
  2134.     Cleanup();
  2135.     return;
  2136.     }
  2137. UtilityBase = OpenLibrary("utility.library",37);
  2138.  if (UtilityBase==NULL)
  2139.     {
  2140.     fprintf(fpOut,"couldn't open utility.library v37!");
  2141.     Cleanup();
  2142.     return;
  2143.     }
  2144. GadToolsBase = OpenLibrary("gadtools.library",37);
  2145.  if (GadToolsBase==NULL)
  2146.     {
  2147.     fprintf(fpOut,"couldn't open gadtools.library v37!\n");
  2148.     Cleanup();
  2149.     return;
  2150.     }
  2151. AslBase = OpenLibrary("asl.library", 37L);
  2152.  if (AslBase == NULL)
  2153.     {
  2154.     fprintf(fpOut,"couldn't open asl.library v37!\n");
  2155.     Cleanup();
  2156.     return;
  2157.     }
  2158. IntuitionBase = OpenLibrary("intuition.library",37);
  2159.  if (IntuitionBase == NULL)
  2160.      {
  2161.      fprintf(fpOut,"Couldn't open intuition.library!\n");
  2162.      Cleanup();
  2163.      return;
  2164.      }
  2165. WorkbenchBase = OpenLibrary("workbench.library",37);
  2166.  if (WorkbenchBase == NULL)
  2167.      {
  2168.      fprintf(fpOut,"Couldn't open workbench.library!\n");
  2169.      Cleanup();
  2170.      return;
  2171.      }
  2172.  
  2173. /* construct program name from version string */
  2174. memset(pnamestring,NUL,20);
  2175. strcpy(pnamestring,version+6);
  2176.  
  2177. memset(searchstring,NUL,sizeof(searchstring));
  2178.  
  2179. if (argc>1) ParseCliArgs(argc,argv);
  2180.      
  2181. /* Now add data to listView */
  2182. /* First, initialize List filelist */
  2183.     
  2184.  if (!(filelist = AllocMem(sizeof(struct List),MEMF_CLEAR)) )
  2185.     {
  2186.     MakeReq("Couldn't create filelist!  Out of memory?",NULL,"Oh, Dear");
  2187.     Cleanup();
  2188.     return();
  2189.     }
  2190.  added_bytes += sizeof(struct List);
  2191.     
  2192.  if (!(getlist = AllocMem(sizeof(struct List),MEMF_CLEAR)) )
  2193.     {
  2194.     MakeReq("Couldn't create getlist!  Out of memory?",NULL,"Oh, Dear");
  2195.     Cleanup();
  2196.     return();
  2197.     }
  2198.  added_bytes += sizeof(struct List);
  2199.     
  2200.  NewList(filelist);
  2201.  NewList(getlist);
  2202.  
  2203.  
  2204.  lockscrnerror = SetupScreen();
  2205.  if (lockscrnerror)
  2206.     {
  2207.     MakeReq("Couldn't open screen!",NULL,"Sigh");
  2208.     Cleanup();
  2209.     return();
  2210.     }
  2211.  
  2212.  screenisopen = 1;
  2213.     
  2214.  winopenerror = OpenmgetWindow();
  2215.  if (winopenerror)
  2216.     {
  2217.     MakeReq("Couldn't open window!",NULL,"Sigh");
  2218.     Cleanup();
  2219.     return();
  2220.     }
  2221.  windowisopen = 1;
  2222.  
  2223.  
  2224.  if (ReadmyFile() > 0)
  2225.         {
  2226.         /* fprintf(fpOut,"After ReadMyFile, added_bytes = %i\n",added_bytes); */
  2227.         /* Put list into top list */
  2228.         
  2229.         /* First, make sure all the menus are enabled. */
  2230.         TurnOnAllMenuItems(mgetMenus);
  2231.         
  2232.         SetMenuValues();
  2233.     
  2234.         GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END); 
  2235.         files_selected = 0;
  2236.     
  2237.         if (noparse) SetWindowTitles(mgetWnd, "Please select desired lines now." , (char *) ~0); 
  2238.                    else ChangeWindowTitle();
  2239.         
  2240.         winsig = 1L << mgetWnd->UserPort->mp_SigBit;
  2241.         while (done==FALSE)
  2242.             {
  2243.             signals = Wait(winsig|appwinsig);
  2244.             if (signals&winsig) handlereturn = HandlemgetIDCMP();
  2245.             if (signals&appwinsig) 
  2246.                 {
  2247.                 while (amsg = (struct AppMessage *) GetMsg(awport))
  2248.                     {
  2249.                     argptr = amsg->am_ArgList;
  2250.                     if (argptr->wa_Name != NULL)
  2251.                         {
  2252.                         strcpy(inputfile,argptr->wa_Name);
  2253.                         if (argptr->wa_Lock != NULL) 
  2254.                             {
  2255.                             olddir = CurrentDir(argptr->wa_Lock);
  2256.                             SetReqDefaults(inputfile);
  2257.                              test = fopen(inputfile,"r");
  2258.                              if (test != NULL)
  2259.                                  {
  2260.                                  fclose(test);
  2261.                                  GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  2262.                                 FreeFileNodes(filelist); 
  2263.                                  FreeMem(filelist,sizeof(struct List));
  2264.                                  added_bytes -= sizeof(struct List);
  2265.                                  ClearPointer(mgetWnd);
  2266.          
  2267.                                  if (!(filelist = AllocMem(sizeof(struct List),MEMF_CLEAR)) )
  2268.                                     {
  2269.                                     MakeReq("AppOpen : Couldn't create filelist!  Out of memory?",NULL,"Ok");
  2270.                                     return;
  2271.                                     }
  2272.                                  added_bytes += sizeof(struct List);
  2273.                     
  2274.                                  filelist_length = 0;
  2275.                                  search_current = NULL;
  2276.                                  index = 0;
  2277.                                  
  2278.                                 NewList(filelist);
  2279.                                  ReadmyFile();
  2280.                                  GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  2281.                                 CurrentDir(olddir);
  2282.                                 }
  2283.                                 else
  2284.                                 DisplayBeep(Scr);
  2285.                             }
  2286.                         }
  2287.                     ReplyMsg((struct Message *) amsg);
  2288.                     }
  2289.                 }
  2290.             }
  2291.         if (windowisopen)  ClosemgetWindow();
  2292.         if (screenisopen)  CloseDownScreen();
  2293.  
  2294.         if (files_selected > 0) 
  2295.             {
  2296.             /* If started from WB and no output name given, stdout won't do much, so... */
  2297.              if ((BStartedFromWB == TRUE)&&((fpOut == stdout)||(fpOut == NULL)))
  2298.              {
  2299.                  fpTemp = fopen("ram:Gadmget.Output","w");
  2300.                  if (fpTemp != NULL) fpOut = fpTemp;
  2301.              }
  2302.             PrintFile(szHeaderFile,0);
  2303.             if (noparse) RawOutputList(getlist);
  2304.                    else OutputList(getlist); 
  2305.             PrintFile(szFooterFile,1);
  2306.             }
  2307.         }
  2308.  
  2309. Cleanup();
  2310.  
  2311. /* fprintf(fpOut,"At end, added_bytes = %i\n",added_bytes); */
  2312.         
  2313. return();    
  2314. }
  2315.  
  2316. #endif
  2317.  
  2318.  
  2319.     
  2320.